#!/usr/bin/env node
import { validatePassword } from './passwordValidator';
import * as readline from 'readline';

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

console.log('密码验证器 - 命令行测试');
console.log('----------------------');

function promptPassword() {
  rl.question('请输入要测试的密码: ', (password) => {
    rl.question('请输入用户名(可选): ', (username) => {
      const result = validatePassword(password, username);
      
      console.log('\n验证结果:');
      console.log(`- 密码: ${password}`);
      console.log(`- 用户名: ${username || '(未提供)'}`);
      console.log(`- 是否合规: ${result.isValid ? '✅ 合规' : '❌ 不合规'}`);
      console.log(`- 详细信息: ${result.message}`);
      if (result.suggestion) {
        console.log(`- 建议密码: ${result.suggestion}`);
      }
      
      console.log('\n----------------------');
      rl.question('是否继续测试? (y/n) ', (answer) => {
        if (answer.toLowerCase() === 'y') {
          promptPassword();
        } else {
          rl.close();
        }
      });
    });
  });
}

promptPassword();
